package c.c.b.a.b.a.i;

import android.os.Build.VERSION;
import android.util.Log;
import c.c.b.a.b.a.e;
import c.c.b.a.b.a.k.f;
import c.c.b.a.b.a0;
import java.io.EOFException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.security.cert.Certificate;
import java.security.cert.TrustAnchor;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Objects;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager;

/* compiled from: AndroidPlatform */
public class a extends e {
    public final Class<?> c;
    public final d<Socket> d;
    public final d<Socket> e;
    public final d<Socket> f;
    public final d<Socket> g;
    public final c h;

    /* compiled from: AndroidPlatform */
    public static final class c {
        public final Method a;
        public final Method b;
        public final Method c;

        public c(Method method, Method method2, Method method3) {
            this.a = method;
            this.b = method2;
            this.c = method3;
        }
    }

    /* compiled from: AndroidPlatform */
    public static final class a extends c.c.b.a.b.a.k.c {
        public final Object a;
        public final Method b;

        public a(Object obj, Method method) {
            this.a = obj;
            this.b = method;
        }

        public List<Certificate> a(List<Certificate> list, String str) throws SSLPeerUnverifiedException {
            try {
                X509Certificate[] x509CertificateArr = (X509Certificate[]) list.toArray(new X509Certificate[list.size()]);
                return (List) this.b.invoke(this.a, new Object[]{x509CertificateArr, "RSA", str});
            } catch (InvocationTargetException e) {
                SSLPeerUnverifiedException sSLPeerUnverifiedException = new SSLPeerUnverifiedException(e.getMessage());
                sSLPeerUnverifiedException.initCause(e);
                throw sSLPeerUnverifiedException;
            } catch (IllegalAccessException e2) {
                throw new AssertionError(e2);
            }
        }

        public boolean equals(Object obj) {
            return obj instanceof a;
        }

        public int hashCode() {
            return 0;
        }
    }

    /* compiled from: AndroidPlatform */
    public static final class b implements f {
        public final X509TrustManager a;
        public final Method b;

        public b(X509TrustManager x509TrustManager, Method method) {
            this.b = method;
            this.a = x509TrustManager;
        }

        public X509Certificate a(X509Certificate x509Certificate) {
            try {
                TrustAnchor trustAnchor = (TrustAnchor) this.b.invoke(this.a, new Object[]{x509Certificate});
                if (trustAnchor != null) {
                    return trustAnchor.getTrustedCert();
                }
                return null;
            } catch (IllegalAccessException e) {
                throw e.f("unable to get issues and signature", e);
            } catch (InvocationTargetException unused) {
                return null;
            }
        }

        public boolean equals(Object obj) {
            boolean z = true;
            if (obj == this) {
                return true;
            }
            if (!(obj instanceof b)) {
                return false;
            }
            b bVar = (b) obj;
            if (!(this.a.equals(bVar.a) && this.b.equals(bVar.b))) {
                z = false;
            }
            return z;
        }

        public int hashCode() {
            return (this.b.hashCode() * 31) + this.a.hashCode();
        }
    }

    public a(Class<?> cls, d<Socket> dVar, d<Socket> dVar2, d<Socket> dVar3, d<Socket> dVar4) {
        Method method;
        Method method2;
        Method method3 = null;
        try {
            Class cls2 = Class.forName("dalvik.system.CloseGuard");
            Method method4 = cls2.getMethod("get", new Class[0]);
            method = cls2.getMethod("open", new Class[]{String.class});
            method3 = cls2.getMethod("warnIfOpen", new Class[0]);
            method2 = method3;
            method3 = method4;
        } catch (Exception unused) {
            method2 = method3;
            method = method2;
        }
        this.h = new c(method3, method, method2);
        this.c = cls;
        this.d = dVar;
        this.e = dVar2;
        this.f = dVar3;
        this.g = dVar4;
    }

    public c.c.b.a.b.a.k.c a(X509TrustManager x509TrustManager) {
        Class cls = String.class;
        try {
            Class cls2 = Class.forName("android.net.http.X509TrustManagerExtensions");
            return new a(cls2.getConstructor(new Class[]{X509TrustManager.class}).newInstance(new Object[]{x509TrustManager}), cls2.getMethod("checkServerTrusted", new Class[]{X509Certificate[].class, cls, cls}));
        } catch (Exception unused) {
            return new c.c.b.a.b.a.k.a(k(x509TrustManager));
        }
    }

    public Object c(String str) {
        c cVar = this.h;
        Method method = cVar.a;
        if (method == null) {
            return null;
        }
        try {
            Object invoke = method.invoke(null, new Object[0]);
            cVar.b.invoke(invoke, new Object[]{str});
            return invoke;
        } catch (Exception unused) {
            return null;
        }
    }

    public String d(SSLSocket sSLSocket) {
        d dVar = this.f;
        String str = null;
        if (dVar == null) {
            return null;
        }
        if ((dVar.a(sSLSocket.getClass()) != null ? 1 : null) == null) {
            return null;
        }
        byte[] bArr = (byte[]) this.f.d(sSLSocket, new Object[0]);
        if (bArr != null) {
            str = new String(bArr, e.j);
        }
        return str;
    }

    public X509TrustManager f(SSLSocketFactory sSLSocketFactory) {
        String str = "sslParameters";
        Object b = e.b(sSLSocketFactory, this.c, str);
        if (b == null) {
            try {
                b = e.b(sSLSocketFactory, Class.forName("com.google.android.gms.org.conscrypt.SSLParametersImpl", false, sSLSocketFactory.getClass().getClassLoader()), str);
            } catch (ClassNotFoundException unused) {
                return super.f(sSLSocketFactory);
            }
        }
        X509TrustManager x509TrustManager = (X509TrustManager) e.b(b, X509TrustManager.class, "x509TrustManager");
        if (x509TrustManager != null) {
            return x509TrustManager;
        }
        return (X509TrustManager) e.b(b, X509TrustManager.class, "trustManager");
    }

    public void g(int i, String str, Throwable th) {
        int i2 = 5;
        if (i != 5) {
            i2 = 3;
        }
        if (th != null) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(str);
            stringBuilder.append(10);
            stringBuilder.append(Log.getStackTraceString(th));
            str = stringBuilder.toString();
        }
        int i3 = 0;
        int length = str.length();
        while (i3 < length) {
            int min;
            int indexOf = str.indexOf(10, i3);
            if (indexOf == -1) {
                indexOf = length;
            }
            while (true) {
                min = Math.min(indexOf, i3 + 4000);
                Log.println(i2, "OkHttp", str.substring(i3, min));
                if (min >= indexOf) {
                    break;
                }
                i3 = min;
            }
            i3 = min + 1;
        }
    }

    public void h(String str, Object obj) {
        c cVar = this.h;
        Objects.requireNonNull(cVar);
        int i = 0;
        if (obj != null) {
            try {
                cVar.c.invoke(obj, new Object[0]);
                i = 1;
            } catch (Exception unused) {
            }
        }
        if (i == 0) {
            g(5, str, null);
        }
    }

    public void i(Socket socket, InetSocketAddress inetSocketAddress, int i) throws IOException {
        IOException iOException;
        String str = "Exception in connect";
        try {
            socket.connect(inetSocketAddress, i);
        } catch (AssertionError e) {
            if (e.q(e)) {
                throw new IOException(e);
            }
            throw e;
        } catch (SecurityException e2) {
            iOException = new IOException(str);
            iOException.initCause(e2);
            throw iOException;
        } catch (ClassCastException e3) {
            if (VERSION.SDK_INT == 26) {
                iOException = new IOException(str);
                iOException.initCause(e3);
                throw iOException;
            }
            throw e3;
        }
    }

    public void j(SSLSocket sSLSocket, String str, List<a0> list) {
        if (str != null) {
            this.d.b(sSLSocket, Boolean.TRUE);
            this.e.b(sSLSocket, str);
        }
        d dVar = this.g;
        if (dVar != null) {
            if ((dVar.a(sSLSocket.getClass()) != null ? 1 : null) != null) {
                Object[] objArr = new Object[1];
                c.c.b.a.a.e eVar = new c.c.b.a.a.e();
                int size = list.size();
                for (int i = 0; i < size; i++) {
                    a0 a0Var = (a0) list.get(i);
                    if (a0Var != a0.HTTP_1_0) {
                        eVar.h0(a0Var.a.length());
                        eVar.s(a0Var.a);
                    }
                }
                try {
                    objArr[0] = eVar.l(eVar.b);
                    this.g.d(sSLSocket, objArr);
                } catch (EOFException e) {
                    throw new AssertionError(e);
                }
            }
        }
    }

    public f k(X509TrustManager x509TrustManager) {
        try {
            Method declaredMethod = x509TrustManager.getClass().getDeclaredMethod("findTrustAnchorByIssuerAndSignature", new Class[]{X509Certificate.class});
            declaredMethod.setAccessible(true);
            return new b(x509TrustManager, declaredMethod);
        } catch (NoSuchMethodException unused) {
            return new c.c.b.a.b.a.k.b(x509TrustManager.getAcceptedIssuers());
        }
    }

    public boolean m(String str) {
        try {
            Class cls = Class.forName("android.security.NetworkSecurityPolicy");
            return n(str, cls, cls.getMethod("getInstance", new Class[0]).invoke(null, new Object[0]));
        } catch (ClassNotFoundException | NoSuchMethodException unused) {
            return true;
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            throw e.f("unable to determine cleartext support", e);
        }
    }

    /* JADX WARNING: Missing exception handler attribute for start block: B:4:0x001d */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Missing block: B:5:?, code skipped:
            r2 = ((java.lang.Boolean) r7.getMethod(r0, new java.lang.Class[0]).invoke(r8, new java.lang.Object[0])).booleanValue();
     */
    /* JADX WARNING: Missing block: B:6:0x002f, code skipped:
            return r2;
     */
    public final boolean n(java.lang.String r6, java.lang.Class<?> r7, java.lang.Object r8) throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException {
        /*
        r5 = this;
        r0 = "isCleartextTrafficPermitted";
        r1 = 0;
        r2 = 1;
        r3 = new java.lang.Class[r2];	 Catch:{ NoSuchMethodException -> 0x001d }
        r4 = java.lang.String.class;
        r3[r1] = r4;	 Catch:{ NoSuchMethodException -> 0x001d }
        r3 = r7.getMethod(r0, r3);	 Catch:{ NoSuchMethodException -> 0x001d }
        r4 = new java.lang.Object[r2];	 Catch:{ NoSuchMethodException -> 0x001d }
        r4[r1] = r6;	 Catch:{ NoSuchMethodException -> 0x001d }
        r6 = r3.invoke(r8, r4);	 Catch:{ NoSuchMethodException -> 0x001d }
        r6 = (java.lang.Boolean) r6;	 Catch:{ NoSuchMethodException -> 0x001d }
        r6 = r6.booleanValue();	 Catch:{ NoSuchMethodException -> 0x001d }
        return r6;
    L_0x001d:
        r6 = new java.lang.Class[r1];	 Catch:{ NoSuchMethodException -> 0x002f }
        r6 = r7.getMethod(r0, r6);	 Catch:{ NoSuchMethodException -> 0x002f }
        r7 = new java.lang.Object[r1];	 Catch:{ NoSuchMethodException -> 0x002f }
        r6 = r6.invoke(r8, r7);	 Catch:{ NoSuchMethodException -> 0x002f }
        r6 = (java.lang.Boolean) r6;	 Catch:{ NoSuchMethodException -> 0x002f }
        r2 = r6.booleanValue();	 Catch:{ NoSuchMethodException -> 0x002f }
    L_0x002f:
        return r2;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.c.b.a.b.a.i.a.n(java.lang.String, java.lang.Class, java.lang.Object):boolean");
    }
}
